package com.zznode.redsun.smartcrm.model;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.zznode.csp.domain.basemodel.DomainBusiness;

/**
 * 客户信息
 * 
 * @author taoping
 * 
 */
@Entity
@Table(name = "b_customer")
@DynamicInsert
@DynamicUpdate
public class Customer extends DomainBusiness {

	private static final long serialVersionUID = 1L;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "personal_id")
	private PersonalInfo personalInfo;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "type_id")
	private CustomerType type;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "level_id")
	private CustomerLevel level;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "profession_id")
	private Profession profession;

	@Column(name = "receive_doc")
	private Boolean receiveDoc;

	@ManyToMany(cascade = { CascadeType.REFRESH }, fetch = FetchType.LAZY)
	@JoinTable(name = "b_customer_hobby", inverseJoinColumns = @JoinColumn(name = "hobby_id"), joinColumns = @JoinColumn(name = "customer_id"))
	private Collection<PersonalHobby> hobbies;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "monthly_income")
	private MonthlyIncome monthlyIncome;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "carmodel_id")
	private CarModel carModel;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "service_user_id")
	private PersonalInfo serviceUser;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "create_user")
	private PersonalInfo createUser;

	public CarModel getCarModel() {
		return carModel;
	}

	public void setCarModel(CarModel carModel) {
		this.carModel = carModel;
	}

	public PersonalInfo getServiceUser() {
		return serviceUser;
	}

	public void setServiceUser(PersonalInfo serviceUser) {
		this.serviceUser = serviceUser;
	}

	public PersonalInfo getCreateUser() {
		return createUser;
	}

	public void setCreateUser(PersonalInfo createUser) {
		this.createUser = createUser;
	}

	public MonthlyIncome getMonthlyIncome() {
		return monthlyIncome;
	}

	public void setMonthlyIncome(MonthlyIncome monthlyIncome) {
		this.monthlyIncome = monthlyIncome;
	}

	public PersonalInfo getPersonalInfo() {
		return personalInfo;
	}

	public void setPersonalInfo(PersonalInfo personalInfo) {
		this.personalInfo = personalInfo;
	}

	public CustomerType getType() {
		return type;
	}

	public void setType(CustomerType type) {
		this.type = type;
	}

	public CustomerLevel getLevel() {
		return level;
	}

	public void setLevel(CustomerLevel level) {
		this.level = level;
	}

	public Profession getProfession() {
		return profession;
	}

	public void setProfession(Profession profession) {
		this.profession = profession;
	}

	public Boolean getReceiveDoc() {
		return receiveDoc;
	}

	public void setReceiveDoc(Boolean receiveDoc) {
		this.receiveDoc = receiveDoc;
	}

	public Collection<PersonalHobby> getHobbies() {
		return hobbies;
	}

	public void setHobbies(Collection<PersonalHobby> hobbies) {
		this.hobbies = hobbies;
	}

	public void addHobby(PersonalHobby hobby) {
		if (null == hobby) {
			return;
		}
		if (null == this.hobbies) {
			this.hobbies = new ArrayList<PersonalHobby>();
		}
		if (!this.hobbies.contains(hobby)) {
			this.hobbies.add(hobby);
		}
	}

	public void removeHobby(PersonalHobby hobby) {
		if (null == this.hobbies || null == hobby) {
			return;
		}
		if (this.hobbies.contains(hobby)) {
			this.hobbies.remove(hobby);
		}
	}
}
